package sg.edu.nus.comp.icreate.ivletalk.utils;

import sg.edu.nus.comp.icreate.ivletalk.LoginActivity;
import sg.edu.nus.comp.icreate.ivletalk.User;
import android.webkit.WebView;
import android.webkit.WebViewClient;

public class LoginWebViewClient extends WebViewClient {
	LoginActivity hostActivity;

	public LoginWebViewClient(LoginActivity hostActivity) {
		super();
		this.hostActivity = hostActivity;
	}

	@Override
	public void onPageFinished(WebView view, String url) {
		int index = url.indexOf("token=");
		User.createInstance(hostActivity.getApplicationContext(), ((WebView) view).toString());
		if (index >= 0) {
			User.createInstance(hostActivity.getApplicationContext(), url.substring(index + 6));
			hostActivity.loginSuccess();
		}
	}
}
